package com.fitz.consumer.config;

import com.fitz.enums.SerializerEnum;
import com.fitz.proxy.ProxyFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author fitz
 * Created  on 2020/6/4
 */
@Deprecated
@Slf4j
@Configuration
@EnableConfigurationProperties(RpcConsumerConfig.class)
public class RpcConsumerAutoConfig {

    @Autowired
    private RpcConsumerConfig rpcConsumerConfig;

    @Bean
    public ProxyFactory init(){
        SerializerEnum serializer = null;
        if (StringUtils.isBlank(rpcConsumerConfig.getSerializerType())){
            serializer = SerializerEnum.HESSIAN2;
        }else {
            serializer = SerializerEnum.find(rpcConsumerConfig.getSerializerType());
            if (serializer == null){
                serializer = SerializerEnum.HESSIAN2;
            }
        }
        log.info("Serializer type:{}",serializer.getType());
        return new ProxyFactory(
                rpcConsumerConfig.getMinPoolSize(),rpcConsumerConfig.getMaxPoolSize(),
                serializer.getCode());
    }
}
